home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / altnline.sty < prev    next >
Text File  |  1993-04-01  |  7KB  |  190 lines

  1. % altnline.sty    Version - 1.1
  2. %
  3. % Disclaimer - Use at your own risk.
  4. %
  5. % James Fortune                 
  6. % Oakland University            
  7. % jafortun@vela.acs.oakland.edu 
  8. %
  9. % Based upon the TUGboat article ``Output Routines: Examples and Techniques.''
  10. % that appeared in Volume 11 (1990), Nos. 1, 3 and 4.
  11. %
  12. % This version incorporates suggestions made by Michal Jaegermann, namely:
  13. %
  14. % * Include explicit reference to the TUGboat article
  15. % * ``You can use \def in style files without violating LaTeX spirit.
  16. %     If you are writing style it is assumed that you know what you are
  17. %     doing. :-)'' --- I don't know what I'm doing so I left the \newcommand
  18. %   and \renewcommand commands as is.
  19. % * Internal macros from style file should be protected against name conflicts
  20. %   with user stuff by inclusion of '@' character in names. --- This is quite
  21. %   reasonable so command names that the user is not expected to use in a
  22. %   LaTeX file have been changed to include the '@' character.
  23. % * He sent a new appendline command that adds numbers on a left margin
  24. %   only that was also inspired by the Salomon article.  He left it as an
  25. %   exercise for me to modify it for two-sided printing.  I probably shouldn't
  26. %   have picked something from the double dangerous bend signs for my first
  27. %   serious attempt at hacking on a style file :-).
  28. % * A global linesSoFar so that lineCount may be set to linesSoFar to deal
  29. %   with box255 being broken from the bottom up.  countlines (or its
  30. %   equivalent) advances linesSoFar by a count of lines on a current page.
  31. % * Use of a decremented remainder variable to determine when to add a number
  32. %   to a line. --- I'm trying to get all the lines first.
  33. % * He advised not trying to combine the countlines and duplicate operations
  34. %   into a single loop.  ``I am afraid that you really have to first count
  35. %   how many lines you have on a page and later use this value to produce
  36. %   line numbers.''
  37. %
  38. % Changes to version 1.1 - Michal Jaegermann, ntomczak@vega.math.ualberta.ca
  39. %
  40. % * Added logic to print line numbers only every \lineCountInterval
  41. % * Added a way to set up ONE range of numbered lines; use \nlinesBoundary
  42. %   to do that. (It is possible to sprinkle your text with \nlinesBoundary
  43. %   commands and they may even do the right thing if you will put them
  44. %   in right places - but this is a hack.)
  45. % * Miscellaneous cleanup
  46. % * Every implicit or explicit \clearpage will still cause
  47. %   'Output routine didn't use all of \box255' message.  Any volunteers
  48. %   who know enough about LaTeX output routine to repair that?
  49. %
  50.    
  51. % \font\sevenrm=cmr7
  52.  
  53. % Rainer showed me how to save the previous \output.  Thanks Rainer.
  54. \newtoks\LaTeX@output
  55. \LaTeX@output = \expandafter{\the\output}
  56.  
  57. \newcommand\zero@ToSp{\parskip=\@ne sp plus\@ne pt
  58.   \renewcommand\vfil{\vskip1sp plus1fil}
  59.   \renewcommand\vfill{\vskip1sp plus1fill}
  60.   \abovedisplayshortskip=\@ne sp plus3pt
  61.   \postdisplaypenalty=\@ne
  62.   \interlinepenalty=\@ne}
  63.  
  64. \zero@ToSp
  65.  
  66.  
  67. \newcount\lin@CountInit  % used to establish lineCount of first line on page
  68. \lin@CountInit=\z@
  69. \newcount\lineCountInterval  % used to determine how often lin@Count is printed
  70. \lineCountInterval=5
  71. %
  72. \newcount\lin@CountStart  % don't print line numbers below this value
  73. \lin@CountStart=\@ne
  74. \newcount\lin@CountFinish  % don't print line numbers higher than this
  75. \lin@CountFinish=\m@ne
  76. %
  77. % A command to set boundaries for line numbering.  Use as:
  78. %   \nlinesBoundary{12}, or \nlinesBoundary[50]{12}
  79. %   \nlinesBoundary[<optional upper limit>]<lower limit>
  80. % Any negative number for an upper limit means number to the very end.
  81. % This is a default!
  82. %
  83. \def\nlinesBoundary{\@ifnextchar[{\nlin@sBoundary}{\nlin@sBoundary[\m@ne]}}
  84. \edef\nlin@sBoundary[#1]#2{%
  85.   \global\lin@CountFinish=#1\relax
  86.   \global\lin@CountStart=#2\relax}
  87.  
  88. \newif\ifa@@lnum  % do we really want to print that line number?
  89.  
  90. \newcount\lin@sSoFar
  91. % remainder from division of \lin@sSoFar by \lineCountInterval
  92. \newcount\total@Rem
  93. % current value of remainder used to produce line numbers
  94. \newcount\lin@rem
  95. % these calculations allow to start with \lin@CountInit different from 0
  96. \newcommand\resetlin@sSoFar{%
  97.   \global\lin@sSoFar=\lin@CountInit
  98.   \total@Rem=\lin@CountInit
  99.   \divide\total@Rem by\lineCountInterval
  100.   \multiply\total@Rem by-\lineCountInterval
  101.   \global\advance\total@Rem by\lin@CountInit}
  102.  
  103. \resetlin@sSoFar
  104.  
  105. \newcount\lin@Count
  106. \newif\ifAnyleft \newcount\pen
  107. \newcommand\count@lines{%
  108.   \global\lin@Count=\lin@sSoFar
  109.   \loop \Anyleftfalse
  110.     \ifdim\lastskip=\z@ \ifdim\lastkern=\z@ \ifnum\lastpenalty=\z@
  111.       \setbox0=\lastbox
  112.     \ifvoid0
  113.     \else \Anylefttrue \global\advance\lin@Count by\@ne
  114.                        \global\advance\total@Rem by\@ne
  115.                        \ifnum\total@Rem=\lineCountInterval
  116.                           \global\total@Rem=\z@
  117.                        \fi\fi
  118.     \else \Anylefttrue \unpenalty \fi
  119.     \else \Anylefttrue \unkern \fi
  120.     \else \Anylefttrue \unskip \fi
  121.   \ifAnyleft \repeat}
  122.  
  123. \newcommand\@duplicate{%
  124.   \loop \Anyleftfalse
  125.     \ifdim\lastskip=\z@ \ifdim\lastkern=\z@ \ifnum\lastpenalty=\z@
  126.       \global\setbox0=\lastbox \ifvoid0 % end of breakup loop
  127.     \else \Anylefttrue                  % box present
  128.       \ifnum\lin@rem=0                  % if remainder non-zero we do not care
  129.         \lin@rem=\lineCountInterval
  130.         \ifnum\lin@Count<\lin@CountStart
  131.           \a@@lnumfalse
  132.         \else
  133.           \ifnum\lin@CountFinish<0      % no upper bound
  134.             \a@@lnumtrue                % print it
  135.           \else
  136.             \ifnum\lin@Count>\lin@CountFinish
  137.               \a@@lnumfalse
  138.             \else
  139.               \a@@lnumtrue              % this is the ticket
  140.             \fi
  141.           \fi
  142.         \fi
  143.       \else
  144.          \a@@lnumfalse
  145.       \fi
  146.       \ifa@@lnum
  147.          \append@line
  148.       \else
  149.          \global\setbox1=\vbox{\box0\unvbox1}
  150.       \fi
  151.       \advance\lin@Count\m@ne
  152.       \advance\lin@rem by\m@ne\fi
  153.     \else \Anylefttrue                  % penalty present
  154.       \pen=\lastpenalty
  155.       \global\setbox1=\vbox{\penalty\pen\unvbox1}\unpenalty\fi
  156.     \else \Anylefttrue                  % kern present
  157.       \dimen0=\lastkern
  158.       \global\setbox1=\vbox{\kern\dimen0\unvbox1}\unkern \fi
  159.     \else \Anylefttrue                  % skip present
  160.       \skip0=\lastskip
  161.       \global\setbox1=\vbox{\vskip\skip0\unvbox1}\unskip \fi
  162.     \ifAnyleft \repeat}
  163.  
  164. \newcommand\append@line{%  attach line number
  165.   \setbox2=\vbox to \z@{\smash{\footnotesize\the\lin@Count}}
  166.   \wd2=25pt                           % that much of space for a line number
  167.   \ifodd\count0                       % on the right margin for odd pages
  168.      \setbox0=\hbox{\box0\rlap{\rule{\wd2}{\z@}\box2}}  
  169.   \else                               % and on the left for even
  170.      \setbox0=\hbox{\llap{\box2}\box0}
  171.   \fi
  172.   \global\setbox1=\vbox{\box0\unvbox1}} % add this to a reconstructed page
  173.  
  174. \newbox\brk    % Use old output definition if page is not to be output
  175. \output={\ifnum\outputpenalty <-\@M
  176.   \output={\LaTeX@output}
  177. \else
  178.   \lin@Count=\lin@sSoFar
  179.   \setbox\brk=\vbox{\unvcopy\@cclv\count@lines}
  180.            \global\setbox1=\vbox{}
  181.            \lin@rem=\total@Rem
  182.   \global\lin@sSoFar=\lin@Count
  183.   \setbox\brk=\vbox{\unvcopy\@cclv\@duplicate}
  184.   \ifdim\ht\brk>\z@\message{Incomplete breakup}\fi
  185.   \ht1=\z@\dp1=\z@
  186.   \global\setbox\@cclv=\vbox to\vsize{\unvbox1}% attempt to get glues back
  187.   \@makecol\@opcol
  188. \fi}
  189. \endinput
  190.